package com.complaintcase.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.complaintcase.common.core.domain.entity.SysUser;
import com.complaintcase.common.utils.poi.ExcelUtilExtend;
import com.complaintcase.system.domain.CaseInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.complaintcase.common.annotation.Log;
import com.complaintcase.common.core.controller.BaseController;
import com.complaintcase.common.core.domain.AjaxResult;
import com.complaintcase.common.enums.BusinessType;
import com.complaintcase.system.domain.CaseBestInfo;
import com.complaintcase.system.service.ICaseBestInfoService;
import com.complaintcase.common.utils.poi.ExcelUtil;
import com.complaintcase.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 优秀录音案例库Controller
 * 
 * @author ruoyi
 * @date 2025-10-28
 */
@RestController
@RequestMapping("/system/infobest")
public class CaseBestInfoController extends BaseController
{
    @Autowired
    private ICaseBestInfoService caseBestInfoService;

    /**
     * 查询优秀录音案例库列表
     */
//    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaseBestInfo caseBestInfo)
    {
        startPage();
        List<CaseBestInfo> list = caseBestInfoService.selectCaseBestInfoList(caseBestInfo);
        return getDataTable(list);
    }
    @Log(title = "导入", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtilExtend<CaseBestInfo> util = new ExcelUtilExtend<CaseBestInfo>(CaseBestInfo.class);
        List<CaseBestInfo> userList = util.importExcel(file.getInputStream(),0);
        Long operName = getUserId();
        String message = caseBestInfoService.importCaseInfo(userList, operName);
        return success(message);
    }
    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtilExtend<CaseBestInfo> util = new ExcelUtilExtend<CaseBestInfo>(CaseBestInfo.class);
        util.importTemplateExcel(response, "导出模板");
    }

    /**
     * 导出优秀录音案例库列表
     */
//    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "优秀录音案例库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseBestInfo caseBestInfo)
    {
        List<CaseBestInfo> list = caseBestInfoService.selectCaseBestInfoList(caseBestInfo);
        ExcelUtilExtend<CaseBestInfo> util = new ExcelUtilExtend<CaseBestInfo>(CaseBestInfo.class);
        util.exportExcel(response, list, "优秀录音案例库数据");
    }

    /**
     * 获取优秀录音案例库详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caseBestInfoService.selectCaseBestInfoById(id));
    }

    /**
     * 新增优秀录音案例库
     */
//    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "优秀录音案例库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseBestInfo caseBestInfo)
    {
        return toAjax(caseBestInfoService.insertCaseBestInfo(caseBestInfo));
    }

    /**
     * 修改优秀录音案例库
     */
//    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "优秀录音案例库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseBestInfo caseBestInfo)
    {
        return toAjax(caseBestInfoService.updateCaseBestInfo(caseBestInfo));
    }

    /**
     * 删除优秀录音案例库
     */
//    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "优秀录音案例库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caseBestInfoService.deleteCaseBestInfoByIds(ids));
    }
}
